<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>Elisa3: twimaster.c File Reference</title>

<link href="tabs.css" rel="stylesheet" type="text/css"/>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="navtree.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="resize.js"></script>
<script type="text/javascript" src="navtree.js"></script>
<script type="text/javascript">
  $(document).ready(initResizable);
</script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>

</head>
<body>
<div id="top"><!-- do not remove this div! -->


<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  
  
  <td style="padding-left: 0.5em;">
   <div id="projectname">Elisa3
   
   </div>
   
  </td>
  
  
  
 </tr>
 </tbody>
</table>
</div>

<!-- Generated by Doxygen 1.7.6.1 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>Globals</span></a></li>
    </ul>
  </div>
</div>
<div id="side-nav" class="ui-resizable side-nav-resizable">
  <div id="nav-tree">
    <div id="nav-tree-contents">
    </div>
  </div>
  <div id="splitbar" style="-moz-user-select:none;" 
       class="ui-resizable-handle">
  </div>
</div>
<script type="text/javascript">
  initNavTree('twimaster_8c.html','');
</script>
<div id="doc-content">
<div class="header">
  <div class="summary">
<a href="#define-members">Defines</a> &#124;
<a href="#func-members">Functions</a>  </div>
  <div class="headertitle">
<div class="title">twimaster.c File Reference</div>  </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><code>#include &lt;avr\io.h&gt;</code><br/>
<code>#include &lt;avr\interrupt.h&gt;</code><br/>
<code>#include &lt;inttypes.h&gt;</code><br/>
<code>#include &lt;compat/twi.h&gt;</code><br/>
<code>#include &quot;<a class="el" href="twimaster_8h_source.html">twimaster.h</a>&quot;</code><br/>
<code>#include &quot;<a class="el" href="usart_8h_source.html">usart.h</a>&quot;</code><br/>
</div><table class="memberdecls">
<tr><td colspan="2"><h2><a name="define-members"></a>
Defines</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="twimaster_8c.html#ae70baf5399951da1e7ad45a0ed890832">cbi</a>(sfr, bit)&#160;&#160;&#160;(_SFR_BYTE(sfr) &amp;= ~_BV(bit))</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="twimaster_8c.html#ac4a5536d9bf092116f88b94797ddc882">sbi</a>(sfr, bit)&#160;&#160;&#160;(_SFR_BYTE(sfr) |= _BV(bit))</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="twimaster_8c.html#a43bafb28b29491ec7f871319b5a3b2f8">F_CPU</a>&#160;&#160;&#160;8000000UL</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">#define&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="twimaster_8c.html#a17ae80300a19853baae9dc086d18bb38">SCL_CLOCK</a>&#160;&#160;&#160;440000L</td></tr>
<tr><td colspan="2"><h2><a name="func-members"></a>
Functions</h2></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="twimaster_8c.html#a255e7886ed9ba7aa5509f7c6234d52fd">i2c_close</a> ()</td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="twimaster_8c.html#a5730d9445429351b9f750084c5cb5aae">i2c_init</a> (void)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">initialize the I2C master interace. Need to be called only once  <a href="#a5730d9445429351b9f750084c5cb5aae"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">unsigned char&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="twimaster_8c.html#aa3d328f00326115e9c660ccc838417c8">i2c_start</a> (unsigned char <a class="el" href="ir__remote__control_8c.html#a9ff470cb16fb31f83ca0b9192a33e402">address</a>)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Issues a start condition and sends address and transfer direction.  <a href="#aa3d328f00326115e9c660ccc838417c8"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="twimaster_8c.html#a0ef0de570e080339e04edb1176807560">i2c_start_wait</a> (unsigned char <a class="el" href="ir__remote__control_8c.html#a9ff470cb16fb31f83ca0b9192a33e402">address</a>)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Issues a start condition and sends address and transfer direction.  <a href="#a0ef0de570e080339e04edb1176807560"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">unsigned char&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="twimaster_8c.html#a70c934b61f3c6ba8524104a1d7197d30">i2c_rep_start</a> (unsigned char <a class="el" href="ir__remote__control_8c.html#a9ff470cb16fb31f83ca0b9192a33e402">address</a>)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Issues a repeated start condition and sends address and transfer direction.  <a href="#a70c934b61f3c6ba8524104a1d7197d30"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">void&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="twimaster_8c.html#ad35d4e4f52ca74b503d5e5e1e0a3f5f3">i2c_stop</a> (void)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Terminates the data transfer and releases the I2C bus.  <a href="#ad35d4e4f52ca74b503d5e5e1e0a3f5f3"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">unsigned char&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="twimaster_8c.html#add947aade44ed6b7f92265f9dec4a711">i2c_write</a> (unsigned char data)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">Send one byte to I2C device.  <a href="#add947aade44ed6b7f92265f9dec4a711"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">unsigned char&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="twimaster_8c.html#a32ac22052d55f93375b024192217db21">i2c_readAck</a> (void)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">read one byte from the I2C device, request more data from device  <a href="#a32ac22052d55f93375b024192217db21"></a><br/></td></tr>
<tr><td class="memItemLeft" align="right" valign="top">unsigned char&#160;</td><td class="memItemRight" valign="bottom"><a class="el" href="twimaster_8c.html#ad89e839fc17b05fbb5dd79897c55234e">i2c_readNak</a> (void)</td></tr>
<tr><td class="mdescLeft">&#160;</td><td class="mdescRight">read one byte from the I2C device, read is followed by a stop condition  <a href="#ad89e839fc17b05fbb5dd79897c55234e"></a><br/></td></tr>
</table>
<hr/><h2>Define Documentation</h2>
<a class="anchor" id="ae70baf5399951da1e7ad45a0ed890832"></a><!-- doxytag: member="twimaster.c::cbi" ref="ae70baf5399951da1e7ad45a0ed890832" args="(sfr, bit)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define <a class="el" href="twimaster_8c.html#ae70baf5399951da1e7ad45a0ed890832">cbi</a></td>
          <td>(</td>
          <td class="paramtype">&#160;</td>
          <td class="paramname">sfr, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">&#160;</td>
          <td class="paramname">bit&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td>&#160;&#160;&#160;(_SFR_BYTE(sfr) &amp;= ~_BV(bit))</td>
        </tr>
      </table>
</div>
<div class="memdoc">

</div>
</div>
<a class="anchor" id="a43bafb28b29491ec7f871319b5a3b2f8"></a><!-- doxytag: member="twimaster.c::F_CPU" ref="a43bafb28b29491ec7f871319b5a3b2f8" args="" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define <a class="el" href="twimaster_8c.html#a43bafb28b29491ec7f871319b5a3b2f8">F_CPU</a>&#160;&#160;&#160;8000000UL</td>
        </tr>
      </table>
</div>
<div class="memdoc">

</div>
</div>
<a class="anchor" id="ac4a5536d9bf092116f88b94797ddc882"></a><!-- doxytag: member="twimaster.c::sbi" ref="ac4a5536d9bf092116f88b94797ddc882" args="(sfr, bit)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define <a class="el" href="twimaster_8c.html#ac4a5536d9bf092116f88b94797ddc882">sbi</a></td>
          <td>(</td>
          <td class="paramtype">&#160;</td>
          <td class="paramname">sfr, </td>
        </tr>
        <tr>
          <td class="paramkey"></td>
          <td></td>
          <td class="paramtype">&#160;</td>
          <td class="paramname">bit&#160;</td>
        </tr>
        <tr>
          <td></td>
          <td>)</td>
          <td></td><td>&#160;&#160;&#160;(_SFR_BYTE(sfr) |= _BV(bit))</td>
        </tr>
      </table>
</div>
<div class="memdoc">

</div>
</div>
<a class="anchor" id="a17ae80300a19853baae9dc086d18bb38"></a><!-- doxytag: member="twimaster.c::SCL_CLOCK" ref="a17ae80300a19853baae9dc086d18bb38" args="" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">#define <a class="el" href="twimaster_8c.html#a17ae80300a19853baae9dc086d18bb38">SCL_CLOCK</a>&#160;&#160;&#160;440000L</td>
        </tr>
      </table>
</div>
<div class="memdoc">

</div>
</div>
<hr/><h2>Function Documentation</h2>
<a class="anchor" id="a255e7886ed9ba7aa5509f7c6234d52fd"></a><!-- doxytag: member="twimaster.c::i2c_close" ref="a255e7886ed9ba7aa5509f7c6234d52fd" args="()" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void <a class="el" href="twimaster_8h.html#a255e7886ed9ba7aa5509f7c6234d52fd">i2c_close</a> </td>
          <td>(</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

</div>
</div>
<a class="anchor" id="a5730d9445429351b9f750084c5cb5aae"></a><!-- doxytag: member="twimaster.c::i2c_init" ref="a5730d9445429351b9f750084c5cb5aae" args="(void)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void <a class="el" href="twimaster_8h.html#a5730d9445429351b9f750084c5cb5aae">i2c_init</a> </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>initialize the I2C master interace. Need to be called only once </p>
<dl class="params"><dt><b>Parameters:</b></dt><dd>
  <table class="params">
    <tr><td class="paramname">void</td><td></td></tr>
  </table>
  </dd>
</dl>
<dl class="return"><dt><b>Returns:</b></dt><dd>none </dd></dl>

</div>
</div>
<a class="anchor" id="a32ac22052d55f93375b024192217db21"></a><!-- doxytag: member="twimaster.c::i2c_readAck" ref="a32ac22052d55f93375b024192217db21" args="(void)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">unsigned char <a class="el" href="twimaster_8h.html#a32ac22052d55f93375b024192217db21">i2c_readAck</a> </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>read one byte from the I2C device, request more data from device </p>
<dl class="return"><dt><b>Returns:</b></dt><dd>byte read from I2C device </dd></dl>

</div>
</div>
<a class="anchor" id="ad89e839fc17b05fbb5dd79897c55234e"></a><!-- doxytag: member="twimaster.c::i2c_readNak" ref="ad89e839fc17b05fbb5dd79897c55234e" args="(void)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">unsigned char <a class="el" href="twimaster_8h.html#ad89e839fc17b05fbb5dd79897c55234e">i2c_readNak</a> </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>read one byte from the I2C device, read is followed by a stop condition </p>
<dl class="return"><dt><b>Returns:</b></dt><dd>byte read from I2C device </dd></dl>

</div>
</div>
<a class="anchor" id="a70c934b61f3c6ba8524104a1d7197d30"></a><!-- doxytag: member="twimaster.c::i2c_rep_start" ref="a70c934b61f3c6ba8524104a1d7197d30" args="(unsigned char address)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">unsigned char <a class="el" href="twimaster_8h.html#a93a9461da34295250ba935bbce9a980d">i2c_rep_start</a> </td>
          <td>(</td>
          <td class="paramtype">unsigned char&#160;</td>
          <td class="paramname"><em>addr</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Issues a repeated start condition and sends address and transfer direction. </p>
<dl class="params"><dt><b>Parameters:</b></dt><dd>
  <table class="params">
    <tr><td class="paramname">addr</td><td>address and transfer direction of I2C device </td></tr>
  </table>
  </dd>
</dl>
<dl class="retval"><dt><b>Return values:</b></dt><dd>
  <table class="retval">
    <tr><td class="paramname">0</td><td>device accessible </td></tr>
    <tr><td class="paramname">1</td><td>failed to access device </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a class="anchor" id="aa3d328f00326115e9c660ccc838417c8"></a><!-- doxytag: member="twimaster.c::i2c_start" ref="aa3d328f00326115e9c660ccc838417c8" args="(unsigned char address)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">unsigned char <a class="el" href="twimaster_8h.html#a58dfadce0c2fee4bfac01df6cd2b4477">i2c_start</a> </td>
          <td>(</td>
          <td class="paramtype">unsigned char&#160;</td>
          <td class="paramname"><em>addr</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Issues a start condition and sends address and transfer direction. </p>
<dl class="params"><dt><b>Parameters:</b></dt><dd>
  <table class="params">
    <tr><td class="paramname">addr</td><td>address and transfer direction of I2C device </td></tr>
  </table>
  </dd>
</dl>
<dl class="retval"><dt><b>Return values:</b></dt><dd>
  <table class="retval">
    <tr><td class="paramname">0</td><td>device accessible </td></tr>
    <tr><td class="paramname">1</td><td>failed to access device </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
<a class="anchor" id="a0ef0de570e080339e04edb1176807560"></a><!-- doxytag: member="twimaster.c::i2c_start_wait" ref="a0ef0de570e080339e04edb1176807560" args="(unsigned char address)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void <a class="el" href="twimaster_8h.html#aee3747a01738315cd5580588994b6c28">i2c_start_wait</a> </td>
          <td>(</td>
          <td class="paramtype">unsigned char&#160;</td>
          <td class="paramname"><em>addr</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Issues a start condition and sends address and transfer direction. </p>
<p>If device is busy, use ack polling to wait until device ready </p>
<dl class="params"><dt><b>Parameters:</b></dt><dd>
  <table class="params">
    <tr><td class="paramname">addr</td><td>address and transfer direction of I2C device </td></tr>
  </table>
  </dd>
</dl>
<dl class="return"><dt><b>Returns:</b></dt><dd>none </dd></dl>

</div>
</div>
<a class="anchor" id="ad35d4e4f52ca74b503d5e5e1e0a3f5f3"></a><!-- doxytag: member="twimaster.c::i2c_stop" ref="ad35d4e4f52ca74b503d5e5e1e0a3f5f3" args="(void)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">void <a class="el" href="twimaster_8h.html#ad35d4e4f52ca74b503d5e5e1e0a3f5f3">i2c_stop</a> </td>
          <td>(</td>
          <td class="paramtype">void&#160;</td>
          <td class="paramname"></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Terminates the data transfer and releases the I2C bus. </p>
<dl class="params"><dt><b>Parameters:</b></dt><dd>
  <table class="params">
    <tr><td class="paramname">void</td><td></td></tr>
  </table>
  </dd>
</dl>
<dl class="return"><dt><b>Returns:</b></dt><dd>none </dd></dl>

</div>
</div>
<a class="anchor" id="add947aade44ed6b7f92265f9dec4a711"></a><!-- doxytag: member="twimaster.c::i2c_write" ref="add947aade44ed6b7f92265f9dec4a711" args="(unsigned char data)" -->
<div class="memitem">
<div class="memproto">
      <table class="memname">
        <tr>
          <td class="memname">unsigned char <a class="el" href="twimaster_8h.html#add947aade44ed6b7f92265f9dec4a711">i2c_write</a> </td>
          <td>(</td>
          <td class="paramtype">unsigned char&#160;</td>
          <td class="paramname"><em>data</em></td><td>)</td>
          <td></td>
        </tr>
      </table>
</div>
<div class="memdoc">

<p>Send one byte to I2C device. </p>
<dl class="params"><dt><b>Parameters:</b></dt><dd>
  <table class="params">
    <tr><td class="paramname">data</td><td>byte to be transfered </td></tr>
  </table>
  </dd>
</dl>
<dl class="retval"><dt><b>Return values:</b></dt><dd>
  <table class="retval">
    <tr><td class="paramname">0</td><td>write successful </td></tr>
    <tr><td class="paramname">1</td><td>write failed </td></tr>
  </table>
  </dd>
</dl>

</div>
</div>
</div><!-- contents -->
</div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Defines</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

  <div id="nav-path" class="navpath">
    <ul>
      <li class="navelem"><a class="el" href="twimaster_8c.html">twimaster.c</a>      </li>

    <li class="footer">Generated on Thu Dec 4 2014 08:30:52 for Elisa3 by
    <a href="http://www.doxygen.org/index.html">
    <img class="footer" src="doxygen.png" alt="doxygen"/></a> 1.7.6.1 </li>
   </ul>
 </div>


</body>
</html>
